﻿// template/template.cpp
// 模板渲染封装类
#include "pch.h"
// 模板渲染使用 inja
// https://github.com/Huiyicc/inja
// https://pantor.github.io/inja/

//void _test_() {
//	inja::Environment env;
//	inja::json data;
//	data["name"] = "world";
//	std::string result = env.render("Hello {{ name }}!", data); // "Hello Inja!"
//}

class PretendEnvironment {
	inja::LexerConfig lexer_config;
	inja::ParserConfig parser_config;
	inja::RenderConfig render_config;

	inja::FunctionStorage function_storage;
	inja::TemplateStorage template_storage;

public:
	std::string input_path;
	std::string output_path;
};


//快速渲染
CXTextA WEBOAT_API WoTemplateQuickRender(const char*input, WoTemplateJson& render) {
	return inja::render(input, render);
}

//创建模板类
WoTemplateEnvironment WEBOAT_API WoTemplateCreate () {
	return std::make_shared<inja::Environment>();
};

//模板类直接渲染
void WEBOAT_API WoTemplateEnvRender(WoTemplateEnvironment& env,const char*tempStr, WoTemplateJson& data,CXTextA& rest) {
	rest = env->render(tempStr, data);
}

//Wo渲染模板_渲染器_文件
void WEBOAT_API WoTemplateEnvRenderFile(WoTemplateEnvironment& env, const char* tempPath, WoTemplateJson& data, CXTextA& rest) {
	rest = env->render_file(tempPath, data);
}

//Wo渲染模板_渲染器_文件json
void WEBOAT_API WoTemplateEnvRenderFileJson(WoTemplateEnvironment& env, const char* tempPath, const char* jsonPath, CXTextA& rest) {
	rest = env->render_file_with_json_file(tempPath, jsonPath);
}
//Wo渲染模板_渲染器_置全局路径
void WEBOAT_API WoTemplateEnvSetGlobalPath(WoTemplateEnvironment& env, const char* path) {
	auto p = (PretendEnvironment*)env.get();
	p->input_path = path;
	p->output_path = path;
}
//Wo渲染模板_渲染器_置输入路径
void WEBOAT_API WoTemplateEnvSetInputPath(WoTemplateEnvironment& env, const char* path) {
	auto p = (PretendEnvironment*)env.get();
	p->input_path = path;
}
//Wo渲染模板_渲染器_置输出路径
void WEBOAT_API WoTemplateEnvSetOutputPath(WoTemplateEnvironment& env, const char* path) {
	auto p = (PretendEnvironment*)env.get();
	p->output_path = path;
}

